Compilation Verification Across Releases

As we know, N4 has a small set of published Groovy API's and then there are a large number of public methods that are exposed usually for inter-module interactions. In some cases, it is possible that your Groovy scripts may be using an N4 API that is not expected to be used externally. Therefore, if an N4 public method is refactored in a minor or major release of N4, you must catch it before you roll out N4 into production.

Navis recommends you follow one of the following suggestions to do this:

  1. Run the following Groovy Code in N4 Admin / DBA / Script Runner Window

import com.Navis.argo.ArgoAssetsEntity

import com.Navis.argo.ArgoAssetsField

import com.Navis.argo.business.api.GroovyApi

import com.Navis.argo.business.atoms.DigitalAssetTypeEnum

import com.Navis.argo.business.event.groovy.GroovyClassCache

import com.Navis.framework.business.Roastery

import com.Navis.framework.portal.QueryUtils

import com.Navis.framework.portal.query.DomainQuery

import com.Navis.framework.portal.query.PredicateFactory

import com.Navis.argo.business.reports.DigitalAsset

/**

* Author : Rafay Khawaja

* Simple Groovy to go over all the groovy codes in the digital assets table and report error if it can't be compiled on the deployed system

* where it is run.

* The code can be enhanced to cover more aspects, this is just a sample. Tested this with 1.0 version groovy,

* to keep it portable. Should you change this, please don't use 1.6 version API's like advanced loop syntax etc here to keep it runnable in all versions of N4.

*/

public class GroovyCompilationTest extends GroovyApi {

public String execute() {

  DomainQuery dq = QueryUtils.createDomainQuery(ArgoAssetsEntity.DIGITAL_ASSET);

  dq.addDqPredicate(PredicateFactory.eq(ArgoAssetsField.DA_FORMAT, DigitalAssetTypeEnum.GROOVY));

  List list = Roastery.getHibernateApi().findEntitiesByDomainQuery(dq);

  Iterator iterator = list.iterator()

  StringBuilder sb = new StringBuilder();

  sb.append("Summary of Groovy Compilation\n");

  String groovyId;

  while (iterator.hasNext()) {

   DigitalAsset da = (DigitalAsset) iterator.next();

   String groovyCode = da.getDaGroovyCode();

   groovyId = da.getDaId();

   try {

    Class groovyClass = new GroovyClassCache().parseGroovy(groovyCode)

    String className = groovyClass.getSimpleName()

    sb.append("SUCCESS : " + groovyId + "\n")

    // in 2.4 following lines can give some hints for runtime violation of groovy 1.8 rules (used in 2.4)

        if (groovyCode.contains("static final") || groovyCode.contains("final static")){

          log(A known bug with Groovy 1.8 prohibits including the 'static' and 'final' modifiers in the same line: " + className);

        }

   } catch (Exception e) {

    sb.append("FAILED : " + groovyId + "\n").append("Stack" + e.getMessage()).append("\n");

   }

  }

  return sb.toString();

}

}

The above groovy script prints a summary of the failures and successes. Sample below

Summary of Groovy Compilation

SUCCESS : DPWAntwerpUnitUpdateGroovyPlugin

SUCCESS : DPWAntwerpGateGroovyPlugin

SUCCESS : DPWAntwerpPrintReservedContainersGroovyPlugin

SUCCESS : DPWAntwerpUnitRetireIDOEmail

SUCCESS : DPWAntwerpUnitFixPodAndObCv

SUCCESS : DPWAntwerpUnitDamageInsert

FAILED : CoherenceTest

Stackkey=ERROR__NULL_MESSAGE parms=[Failed to parse groovy action:

org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, script1300321791303.groovy: 6: unable to resolve class com.Navis.xpscache.ParticipantCacheManager

  1. Set up an IDE (Eclipse, IDEA, or any other IDE) project that contains all of your groovy scripts and the latest N4 Jar files.

Try to compile the project in the IDE. If it fails, it indicates incompatibility between N4 Jar files and the existing Groovy scripts.

  1. Write an Ant project that performs the same function as the IDE above.

For this you need to download Ant from Apache's website and create an Ant project containing your Groovy scripts and the latest N4 Jar files.

If the Ant project fails to compile the Groovy script(s), it indicates incompatibility and you should resolve the issue before you roll out the new N4 version into production.

The above recommendations address only compilation issues not the runtime changes in the behavior of the API's. To verify the runtime behavior changes (semantics), you need to do actual use case testing in a deployed environment. This check only verifies all the groovy that is in the plugins folder.